package com.clear.prototype.deepwcopy.recursionclone;

public class Client {
    public static void main(String[] args) throws Exception {
        DeepProtoType p = new DeepProtoType();
        p.name = "张三";
        p.deepCloneableTarget = new DeepCloneableTarget("牛气", "牛");

        // 方式一（递归克隆）完成深拷贝
        DeepProtoType p2 = (DeepProtoType) p.clone();

        // p 和 p2 的deepCloneableTarget hashcode不一致，则说明实现类深拷贝
        System.out.println(p.name + " " + p.deepCloneableTarget + " " + p.deepCloneableTarget.hashCode());
        System.out.println(p2.name + " " + p2.deepCloneableTarget + " " + p2.deepCloneableTarget.hashCode());

        // 方式二完成深拷贝
        DeepProtoType p3 = (DeepProtoType) p.deepClone();

        // p 和 p3 的deepCloneableTarget hashcode不一致，则说明实现类深拷贝
        System.out.println(p.name + " " + p.deepCloneableTarget + " " + p.deepCloneableTarget.hashCode());
        System.out.println(p3.name + " " + p3.deepCloneableTarget + " " + p3.deepCloneableTarget.hashCode());
    }
}